<template>
	<view class="page-wrap" :data-theme="theme" :class="theme" :style="globalColor.style">
		<HeadCustom></HeadCustom>
		<view class="content-wrap bg-F7F8FF">
			<view class="input-item bg-base">
				<textarea class="uni-input font28" v-model="fromData.intelligenceVoiceText" placeholder-style="color:#969699" placeholder="请输入文字简介" maxlength="500" />
				<view class="count fboxRow Ycenter Xend font24 color-969699">{{ (fromData.intelligenceVoiceText && fromData.intelligenceVoiceText.length) || 0 }}/200</view>
			</view>
			<view class="input-tips fboxRow Ycenter font24 color-969699">请输入文字简介，限200字</view>
		</view>
		<BottomBtn title="保存" @btnClick="verifyTap"></BottomBtn>
	</view>
</template>

<script>
import BottomBtn from '@/components/bottom-btn/index.vue';
import { strTrim } from '@/static/js/common.js';
import { getCardVoice, cardVoiceUpdate } from '@/api/card.js';
export default {
	components: { BottomBtn },
	data() {
		return {
			theme: getApp().globalData.appTheme,
			globalColor: getApp().globalData.globalColor,
			fromData: {
				auditStatus: '',
				customVoiceUrl: '',
				intelligenceVoiceText: '',
				reason: '',
				voiceType: ''
			}
		};
	},
	onShow() {
		this.getVoice();
	},
	methods: {
		getVoice(data) {
			getCardVoice().then(res => {
				this.fromData = res.data;
			});
		},
		verifyTap() {
			const { intelligenceVoiceText } = this.fromData;
			if (strTrim(intelligenceVoiceText)) {
				this.putInfo();
			} else {
				uni.showToast({
					icon: 'none',
					title: '请输入文字简介'
				});
			}
		},
		async putInfo() {
			const { intelligenceVoiceText } = this.fromData;
			let pages = getCurrentPages(); // 当前页面
			let beforePage = pages[pages.length - 2]; // 前一个页面
			// uni.navigateBack({
			// 	success: function() {
			// 		beforePage.$vm.getVoice({ intelligenceVoiceText }); // 执行前一个页面的刷新
			// 	}
			// });
			uni.showLoading({
				title:'保存中'
			})
			await cardVoiceUpdate(this.fromData).then(res=>{
				if(res.data){
					uni.navigateBack()
					// let pages = getCurrentPages(); // 当前页面
					// let beforePage = pages[pages.length - 2]; // 前一个页面
					// uni.navigateBack({
					// 	success: function() {
					// 		beforePage.$vm.getVoice({intelligenceVoiceText}); // 执行前一个页面的刷新
					// 	}
					// })
				}
			}).finally(()=>{
				uni.hideLoading()
			})
		}
	}
};
</script>

<style lang="scss" scoped>
.page-wrap{
	min-height: 100vh;
}
.content-wrap{
	// padding: 40rpx;
}
.input-item {
	padding: 40rpx;
}
.uni-input {
	width: 650rpx;
	height: 220rpx;
	line-height: 46rpx;
	padding: 10rpx;
	border-radius: 12rpx;
	background-color: var(--viewBgColor);
}
.count{
	margin-top: 15rpx;
}
.input-tips {
	padding: 0 40rpx;
	color: var(--contentFontFourColor);
}
</style>
